package com.fang.ssmhe.controller;

import com.fang.ssmhe.bean.User;
import com.fang.ssmhe.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UserController {

    @Autowired //为我们注入一个定义好的 bean
    private UserService userService;

    @RequestMapping("/golog")
    public String log(User user, Model model) {
        User u = userService.findOne(user);
        model.addAttribute("user", u);
        if (u != null) {
            return "index";
        } else
            return "login";
    }

    @RequestMapping("/goreg")
    public String reg(User user) {
        User u = userService.checkReg(user.getUsername());
        if (u == null) {
            userService.addOne(user);
            return "regok";
        }
        return "regno";
    }

    @RequestMapping("/reg")
    public String reg(String string){
        return "reg";
    }


}
